<%--
  Created by IntelliJ IDEA.
  User: FT
  Date: 2020/9/22
  Time: 15:30
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>用户列表</title>
    <style>
        table{
            margin-left: 5%;
            width: 90%;
            text-align: center;
        }
        table tr{
            height: 50px;
        }
        table th{
            text-align: center;
        }
        .search{
            margin-top: 1%;
            margin-left: 5%;
        }
        .page{
            width: 25%;
            height: 50px;
            margin: 10px auto;
        }
        .page button{
            height: 30px;
            margin-left: 5px;
            width: 60px;
        }
        .insert{
            margin-left: 5%;
            height: 30px;
            width: 80px;
            margin-top: 20px;
        }
    </style>
</head>
<body>
<jsp:include page="/html/commons/top.jsp"></jsp:include>
<jsp:include page="/html/commons/menu.jsp"></jsp:include>
<div id="right">
<%--    <button class="insert" onclick="location.href='${pageContext.request.contextPath}/add.jsp'">添加用户</button>--%>
    <%--模糊查询，搜索功能--%>
    <form action="${pageContext.request.contextPath}/user/list" method="post">
        <input class="search" type="text" name="name" placeholder="请输入您要搜索的姓名">
        <input type="submit" value="搜索">
    </form>
    <table border="1" cellspacing="0">
        <th>序列号</th>
        <th>用户名</th>
        <th>真实姓名</th>
        <th>年龄</th>
        <th>性别</th>
        <th>部门</th>
        <th>手机号</th>
        <th>注册时间</th>
        <th>邮箱</th>
        <th>操作</th>
        <c:forEach var="u" items="${page.items}" varStatus="status">
            <tr>
                <td>${status.count}</td>
                <td>${u.username}</td>
                <td>${u.realName}</td>
                <td>${u.age}</td>
                <c:if test="${u.gender==1}">
                    <td>男</td>
                </c:if>
                <c:if test="${u.gender==0}">
                    <td>女</td>
                </c:if>
                <c:if test="${u.gender!=0&&u.gender!=1}">
                    <td>人妖</td>
                </c:if>
                <td>${u.deptName}</td>
                <td>${u.phone}</td>
                <td>${u.registerTime}</td>
                <td>${u.email}</td>
                <td>
                    <a href="${pageContext.request.contextPath}/user/delete?id=${u.id}&currentPage=${page.pageNo}&name=${name}">删除</a>
                    <a href="${pageContext.request.contextPath}/user/toEdit?id=${u.id}">修改</a>
                </td>
            </tr>
        </c:forEach>
    </table>
        <%--分页--%>
        <div class="page">
            <button onclick="location.href = '${pageContext.request.contextPath}/user/list?currentPage=1&name=${name}'">首页</button>
            <%--上一页--%>
            <c:if test="${page.pageNo==1}">
                <button>上一页</button>
            </c:if>
            <c:if test="${page.pageNo>1}">
                <button onclick="location.href = '${pageContext.request.contextPath}/user/list?currentPage=${page.pageNo-1}&name=${name}'">上一页</button>
            </c:if>
            <c:forEach var="pageNum" begin="1" end="${page.pageTotal}">
                <c:if test="${pageNum==page.pageNo}">
                    <a>${page.pageNo}</a>
                </c:if>
                <c:if test="${pageNum!=page.pageNo}">
                    <a href="${pageContext.request.contextPath}/user/list?currentPage=${pageNum}&name=${name}">${pageNum}</a>
                </c:if>
            </c:forEach>
            <%--下一页--%>
            <c:if test="${page.pageNo==page.pageTotal}">
                <button>下一页</button>
            </c:if>
            <c:if test="${page.pageNo<page.pageTotal}">
                <button onclick="location.href = '${pageContext.request.contextPath}/user/list?currentPage=${page.pageNo+1}&name=${name}'">下一页</button>
            </c:if>
            <button onclick="location.href = '${pageContext.request.contextPath}/user/list?currentPage=${page.pageTotal}&name=${name}'">尾页</button>
        </div>
</div>
</body>
</html>
